
**********************************************************************************************************
** Article: Is it Possible to Predict Electoral Abstention on the Individual Level?						**
**			A Preregistered Test on Forecasting the Effects of Abolishing Compulsory Voting in Belgium	**
** Journal: International Journal of Forecasting														**
** Date:	April 2025		 																			**
** Authors:	Stiers & Hooghe																				**
**********************************************************************************************************

*** Replication of prediction model A ***
***Load dataset
use "Replication_prediction_Model_A.dta"

***Estimate model predicting turnout (Table 2 Model A)
logit Turnout Age Age2 i.Gender i.Education Income Interest i.PartyID Trust Knowledge i.Past_turnout
*Calculate predicted probability of turnout for BelREP respondents
predictnl predictedturnout = predict(pr) if Dataset==0
*Calculate predicted probabilities reported in the text
margins, at(Knowledge=(0 1))
margins, at(Past_turnout=(0 1 2))

***Create groups of voters
//Likely voters
egen pc20=pctile(predictedturnout) if Dataset==0, p(20)
gen top80=(predictedturnout>pc20) if  Dataset==0 & predictedturnout~=.
//Unlikely voters
egen pc10=pctile(predictedturnout) if Dataset==0, p(10)
gen middle10=(predictedturnout<pc20&predictedturnout>pc10) if Dataset==0 & predictedturnout~=.
//Non-voters
gen lowest10=(predictedturnout<pc10) if  Dataset==0 & predictedturnout~=.

*Create indicator of groups
gen groups=1 if lowest10==1
replace groups=2 if middle10==1
replace groups=3 if top80==1
label define Groups 1 "Non-voter" 2 "Unlikely voter" 3 "Likely voter"
label values group Groups

*Histogram showing prediction and groups (Figure 1, left panel)
hist predictedturnout , percent width(0.01) title("Model A") xtitle("Predicted probability turnout") ytitle("Percentage of observations") addplot(pci 0 0.8757811 15 0.8757811 0 0.928792 15 0.928792) text(11 0.86 "10th percentile" 11 0.913 "20th percentile", placement(c) orient(vertical)) legend(off) name(F1,replace)


*** Replication of prediction model A ***
***Load dataset
use "Replication_prediction_Model_B.dta",clear

***Estimate model predicting turnout (Table 2 Model B)
logit Turnout Age Age2 i.Gender i.Education Income Interest i.PartyID Trust i.countrydummy2 i.countrydummy3 i.countrydummy4 , cluster(cntry)
*Calculate predicted probability of turnout for BelREP respondents
predictnl predictedturnout = predict(pr) if Dataset==0
*Calculate predicted probabilities reported in the text
margins, at(Age=(0(0.1)1))
margins, at(Income=(0(0.1)1))
margins, at(Interest=(0(0.1)1))

***Create groups of voters
//Likely voters
egen pc20=pctile(predictedturnout) if Dataset==0, p(20)
gen top80=(predictedturnout>pc20) if  Dataset==0 & predictedturnout~=.
//Unlikely voters
egen pc10=pctile(predictedturnout) if Dataset==0, p(10)
gen middle10=(predictedturnout<pc20&predictedturnout>pc10) if Dataset==0 & predictedturnout~=.
//Non-voters
gen lowest10=(predictedturnout<pc10) if  Dataset==0 & predictedturnout~=.

*Create indicator of groups
gen groups=1 if lowest10==1
replace groups=2 if middle10==1
replace groups=3 if top80==1
label define Groups 1 "Non-voter" 2 "Unlikely voter" 3 "Likely voter"
label values group Groups

*Histogram showing prediction and groups (Figure 1, right panel)
hist predictedturnout , percent width(0.01) title("Model B")xtitle("Predicted probability turnout") ytitle("Percentage of observations") addplot(pci 0 0.8183768 15 0.8183768 0 0.8744605 15 0.8744605) text(11 0.805 "10th percentile" 11 0.862 "20th percentile", placement(c) orient(vertical)) legend(off) name(F2,replace)

***Full Figure 1
graph combine F1 F2 , ycommon xsize(9)


*** Appendices ***
***Appendix D
*Table D.1 Model A
use "Replication_prediction_Model_A.dta",clear
logit Turnout Age Age2 i.Gender i.Education Income Interest i.PartyID Trust Knowledge if Past_turnout~=.
*Table D.1 Model B: see code above
